<template>
  <view>
    <view style="margin: 20px">
      <button @click="uploadVoice">上传</button>
      <view class="ver-layout">
        <view v-for="(item,index) in audioList" :key="index" style="margin-top: 10px">
          <sy-audio isCountDown :ref="item.fileName" :src='item.fileFullPath' audioCover='' subheading=''
                    :audioTitle='item.fileName'></sy-audio>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: "voice",
  data() {
    return {
      audioList: []
    }
  },
  methods: {
    uploadVoice() {
      let _this = this
      uni.chooseFile({
        count: 1,
        extension: ['.mp3'],
        success: function (res) {
          let tempFilePaths = res.tempFilePaths
          console.log("chooseFile==", JSON.stringify(res.tempFilePaths));
          uni.uploadFile({
            url: 'http://mdej.impc.com.cn/hlwyy/basis-file/fileOperate/uploadFile', //仅为示例，非真实的接口地址
            filePath: tempFilePaths[0],
            name: 'filedata',
            formData: {
              'xtbh': 'hlwyy'
            },
            success: (uploadFileRes) => {
              // let timeOut = 0
              let timeOut = 500
              let {data} = JSON.parse(uploadFileRes.data)
              let prePath = "http://mdej.impc.com.cn/hlwyy/business-ggfw/fileFeign/downloadFile?fileFullPath="
              data.fileFullPath = prePath + data.fileFullPath
              setTimeout(() => {
                _this.audioList.push(data)
              }, timeOut)
              console.log("uploadVoice", data.fileFullPath);
            }
          });
        }
      });
    }
  }
}
</script>

<style scoped>
.ver-layout {
  display: flex;
  flex-direction: column;
}
</style>
